#include <boost/interprocess/ipc/message_queue.hpp>
#include <iostream>
#include <vector>

using namespace boost::interprocess;
using namespace std ;
const int BUFFER_SIZE = 256 ;
int main ()
{
    try{

        //Open a message queue.
        message_queue mq
            (open_only        //only create
             ,"message_queue"  //name
            );

        unsigned int priority;
        std::size_t recvd_size;
        char buffer[BUFFER_SIZE] ;

        mq.receive(&buffer, BUFFER_SIZE, recvd_size, priority);
        std::cout<< "\n1:\n" << buffer << endl << "recvd_size=" << recvd_size;
        mq.receive(&buffer, BUFFER_SIZE, recvd_size, priority);
        std::cout<< "\n2:\n" << buffer << endl << "recvd_size=" << recvd_size;
        mq.receive(&buffer, BUFFER_SIZE, recvd_size, priority);
        std::cout<< "\n3:\n" << buffer << endl << "recvd_size=" << recvd_size;
    }

    catch(interprocess_exception &ex){
        message_queue::remove("message_queue");
        std::cout << ex.what() << std::endl;
        return 1;
    }
    message_queue::remove("message_queue");
    return 0;
}

